<template >
	<div class="content">
		<div class="content-header" style="display: flex;align-items: center;justify-content: space-between;padding:0 20px;text-indent: 0;">
			<span>{{pageInfo.name}}成绩单</span>
			<el-button type="primary" size="small" @click="$router.go(-1)">返 回</el-button>
		</div>
		<div class="content-table"
		>
			<el-table
					:data="tableData"
					stripe
			>
				<el-table-column
						prop="number"
						label="自增编号"
						align="center"
				>
				</el-table-column>
				<el-table-column
						prop="user.userName"
						label="学生姓名"
						align="center"
				>
				</el-table-column>
				<el-table-column
						prop="score"
						label="认知模块"
						align="center"
				>
					<template slot-scope="scope">
						{{scope.row.score}}(120)
					</template>
				</el-table-column>
				<el-table-column
						label="发酵操作模块"
						align="center"
				>
					<template slot-scope="scope">
						{{scope.row.czScore}}(200)
					</template>
				</el-table-column>
				<el-table-column
						label="检修维护模块"
						align="center"
				>
					<template slot-scope="scope">
						{{scope.row.wxScore}}(30)
					</template>
				</el-table-column>
				<el-table-column
						label="车间设计模块"
						align="center"
				>
					<template slot-scope="scope">
						{{scope.row.cjScore}}(100)
					</template>
				</el-table-column>
				<el-table-column
						label="总分"
						align="center"
				>
					<template slot-scope="scope">
						{{scope.row.allScore}}(450)
					</template>
				</el-table-column>
				<el-table-column
						prop="createTime"
						label="考核时间"
						show-overflow-tooltip
						align="center"
				>
				</el-table-column>
				<el-table-column
						label="操作"
						align="center"
				>
					<template slot-scope="scope">
						<el-button type="primary" size="mini" @click="downLoadStudent(scope.row)">下载报告</el-button>
					
					</template>
				</el-table-column>
			</el-table>
		</div>
		<div class="content-footer">
			<el-pagination
					@size-change="handleSizeChange"
					@current-change="handleCurrentChange"
					background
					:page-size="10"
					small
					layout="total, prev, pager, next, jumper"
					:total="total">
			</el-pagination>
		</div>
	</div>
</template >

<script >
	import {classDownStudent} from "../api/class";
    import request from "../utils/request";
    import common from "../utils/common";

    export default {
        data(){
            return{
                pageInfo:{},
                tableData:[],
                total:null,
				form:{
                    classId: null,
                    pageIndex: 1,
                    pageSize: 10
				}
            }
        },
		created() {
            this.pageInfo=JSON.parse(sessionStorage.getItem('pageForm'))
			this.form.classId = this.pageInfo.id
            console.log(' this.pageInfo', this.pageInfo)
        },
        mounted() {
            this.getList()
        },
        methods: {
            //查询列表
            async getList(){
                const { data } = await classDownStudent(this.form)
             
                if (data.code === 200){
                    this.tableData = data.data.data
                    this.total = data.data.total
                }
            },
            downLoadStudent(item){
                this.$confirm('下载当前学生成绩, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.downloadFile(item)
                })
			},
            //下载班级成绩
            downloadFile(item) {
                request({
                    url: common.requestUrl + "/class/exportClassOne?scoreId=" + item.id,
                    method: 'get',
                    responseType: 'blob',
                }).then(resp => {
                    console.log('ppp', resp)
                    const blob = new Blob([resp.data], {type: "application/vnd.ms-excel"});
                    const url = window.URL.createObjectURL(blob);
                    let a = document.createElement('a');
                    a.download = item.user.userName + '的成绩.xls';
                    a.href = url;
                    a.click();
                })  //导出文件请求
            },
            //分页
            handleSizeChange(val) {
                this.form.pageSize = val
                this.getList()
            },
            handleCurrentChange(val) {
                this.form.pageIndex = val
                this.getList()
            }
        },
    }
</script >

<style scoped lang="less" >
	@import "../assets/style/common";
</style >
